// add(1)(2)(3)()=6
// add(1,2,3)(4)()=10

function curry(fn, newArr = []) {
  let num = []
  return function (...args) {
    num = [...args, ...newArr]
    if (fn.length == num.length) {
      return fn(...num)
    } else {
      return curry(fn, num)
    }
  }
}



let add = curry(function (a, b, c, d) {
  return a + b + c + d
})


console.log(add(1, 2, 3)(4));


